﻿using SuperX.Common.Helper;
using System;

namespace SuperX.Common.Object
{
    public abstract class DEntityBase : PrimaryKeyEntity
    {
        public virtual DateTime? CreatedTime { get; set; }

        public virtual DateTime? UpdatedTime { get; set; }

        public virtual string CreatedUserId { get; set; }

        public virtual string CreatedUserName { get; set; }

        public virtual string UpdatedUserId { get; set; }

        public virtual string UpdatedUserName { get; set; }

        public virtual bool IsDeleted { get; set; } = false;

        public virtual void Create()
        {
            //string text = App.User.FindFirst("UserId")?.Value;
            //string createdUserName = App.User.FindFirst("Account")?.Value;
            Id = string.IsNullOrEmpty(Id) ? GenerateUid.GenerateSnowFlake().ToString() : Id;
            //CreatedTime = DateTime.Now;
            //if (!string.IsNullOrEmpty(text))
            //{
            //    CreatedUserId = long.Parse(text);
            //    CreatedUserName = createdUserName;
            //}
            //else
            //{
            //    CreatedUserId = 142307070910552L;
            //    CreatedUserName = "admin";
            //}
        }

        public virtual void Modify()
        {
            //string text = App.User.FindFirst("UserId")?.Value;
            //string updatedUserName = App.User.FindFirst("Account")?.Value;
            //UpdatedTime = DateTime.Now;
            //if (!string.IsNullOrEmpty(text))
            //{
            //    UpdatedUserId = long.Parse(text);
            //    UpdatedUserName = updatedUserName;
            //}
        }

        public virtual void Delete()
        {
            //string text = App.User.FindFirst("UserId")?.Value;
            //string updatedUserName = App.User.FindFirst("Account")?.Value;
            //UpdatedTime = DateTime.Now;
            //if (!string.IsNullOrEmpty(text))
            //{
            //    UpdatedUserId = long.Parse(text);
            //    UpdatedUserName = updatedUserName;
            //    IsDeleted = true;
            //}
        }

        public virtual string[] UpdateColumn()
        {
            return new string[3] { "UpdatedUserId", "UpdatedUserName", "UpdatedTime" };
        }

        public virtual string[] FalseDeleteColumn()
        {
            string[] array = UpdateColumn();
            string[] array2 = new string[1] { "IsDeleted" };
            string[] array3 = new string[array.Length + array2.Length];
            array2.CopyTo(array3, 0);
            array.CopyTo(array3, array2.Length);
            return array3;
        }
    }
}